package com.mesnac.test;

public class FlagObject {

	private boolean flag;
	public FlagObject(boolean flag){
		this.flag = flag;
	}
	
	public synchronized void createOne(){
		if (flag) {
			try {
				this.wait();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		// create one
		flag = true;
		try{
			Thread.sleep(1000);
		}catch(Exception e){
			
		}
		
		System.out.println("create one");
		this.notify();
	}
	
	public synchronized void useOne(){
		if (!flag) {
			try {
				this.wait();
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		flag = false;
		
		try{
			Thread.sleep(1000);
		}catch(Exception e){
			
		}
		System.out.println("use one");
		this.notify();
	}
}
